<?php

class Page{
	private $TotalPage;//总页数
	private $SelfPage;//当前页数
	private $Url;//url地址
	private $Row;//每页显示数量
	public function __construct($Total,$Row=10){
		$this->Row = $Row;
		$this->TotalPage = ceil($Total/$Row);
		$this->SelfPage = isset($_GET['page'])?min(intval($_GET['page']),$this->TotalPage):1;
		$this->Url = $this->getUrl();//获取url地址信息
	}

	private function getUrl(){
		$url = __WEB__.'?';
		if(isset($_GET['page'])) unset($_GET['page']);
		foreach ($_GET as $key => $value) {
			$url .= $key .'='.$value.'&';
		}
		$url .= 'page=';
		return $url;
	}

	public function limit(){
		return ($this->SelfPage-1)*$this->Row.','.$this->Row;
	}
	public function show(){
		$html = '';
		for ($i=1; $i <= $this->TotalPage ; $i++) { 
			if($i == $this->SelfPage){
				$html .= "{$i}";
			}else{
				$url = $this->getUrl().$i;
				$html .= "<a href='{$url}'>{$i}</a>";
			}
		}
		return $html;
	}

	public function showli(){
		$html = '';
		for ($i=1; $i <= $this->TotalPage ; $i++) { 
			if($i == $this->SelfPage){
				$html .= "<li class='paginItem'><a href=''><span style='color:#333;'>{$i}</span></a></li>";
			}else{
				$url = $this->getUrl().$i;
				$html .= "<li class='paginItem'><a href='{$url}'>{$i}</a></li>";
			}
		}
		return $html;
	}


	public function show_b(){
		$html = '';
		for ($i=1; $i <= $this->TotalPage ; $i++) { 
			if($i == $this->SelfPage){
				$html .= "<b>{$i}</b>";
			}else{
				$url = $this->getUrl().$i;
				$html .= "<a href='{$url}'>{$i}</a>";
			}
		}
		return $html;
	}


}


?>